const Database = require('better-sqlite3');
const db = new Database('data/delivery-management.db');

console.log('=== DEVICES TABLE ===');
const devices = db.prepare('SELECT * FROM devices LIMIT 5').all();
console.log('Device records:', devices.length);
if (devices.length > 0) {
  console.log('Sample device:');
  const device = devices[0];
  Object.keys(device).forEach(key => {
    if (device[key] !== null && device[key] !== '') {
      console.log(`  ${key}: ${device[key]}`);
    }
  });
}

console.log('\n=== DEVICE_TYPE_MAPPINGS TABLE ===');
const mappings = db.prepare('SELECT * FROM device_type_mappings WHERE naming_table = "table_c2" OR position_table = "table_c6" OR base_params_table = "table_c494"').all();
console.log('Relevant mappings:', mappings.length);
mappings.forEach(mapping => {
  console.log(`${mapping.specialty}: ${mapping.classification_name}`);
  console.log(`  naming: ${mapping.naming_table}, position: ${mapping.position_table}, params: ${mapping.base_params_table}`);
  console.log(`  classification_code: ${mapping.classification_code}`);
});

// Check what device uses these parameter tables
console.log('\n=== DEVICES USING THESE PARAMETER TABLES ===');
const devicesUsingTables = db.prepare('SELECT d.*, dtm.classification_name FROM devices d JOIN device_type_mappings dtm ON d.classification_code = dtm.classification_code WHERE dtm.naming_table = "table_c2" OR dtm.position_table = "table_c6" OR dtm.base_params_table = "table_c494"').all();
console.log('Devices using these tables:', devicesUsingTables.length);
devicesUsingTables.forEach(device => {
  console.log(`  ${device.device_id}: ${device.设备表及材料表中的实体对象名称} (${device.classification_name})`);
});

db.close();